package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.CarRenewalStatus;
import com.ygxsk.carhome.response.CarRenewalBean;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-09-18  17:21
 * @Description:一键续保的实体适配器 CarRenewalBean
 */
public class CarRenewalAdapter extends BaseQuickAdapter<CarRenewalBean, BaseViewHolder> {

    //填充一个代理进去,因为涉及到权限申请 放在activity之中用；
//    private BGANinePhotoLayout.Delegate bgaNinePhotoLayoutDelegate;

//    public void setBgaNinePhotoLayoutDelegate(BGANinePhotoLayout.Delegate _bgaNinePhotoLayoutDelegate) {
//        bgaNinePhotoLayoutDelegate = _bgaNinePhotoLayoutDelegate;
//    }

    public CarRenewalAdapter(int layoutResId, @Nullable List<CarRenewalBean> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.textViewPersonPhoneValue, R.id.roundTextViewViewTakeOrder, R.id.roundTextViewViewCompleteOrder);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CarRenewalBean carRenewalBean) {

        if (carRenewalBean != null) {

            //filldatas
            //联系人
            String name = carRenewalBean.getName();

            //手机号
            String phone = carRenewalBean.getPhone();

            //车牌号
            String licenseNo = carRenewalBean.getLicenseNo();

            //身份证号
            String idCard = carRenewalBean.getIdCard();

            //创建的时间
            String createTime = carRenewalBean.getCreateTime();

            //行车本是一个单张图片
//            String drivingNotebook = carRenewalBean.getDrivingNotebook();


            //状态的 数值格式
            String status = carRenewalBean.getStatus();

            //状态值
            String statusString = carRenewalBean.getStatusString();

            //行车本？

            //findView
            //姓名
            TextView textViewPersonValue = (TextView) baseViewHolder.getView(R.id.textViewPersonValue);
            //状态值内容
            TextView textViewPersonOrderState = (TextView) baseViewHolder.getView(R.id.textViewPersonOrderState);
            //手机号
            TextView textViewPersonPhoneValue = (TextView) baseViewHolder.getView(R.id.textViewPersonPhoneValue);
            //车牌号
            TextView textViewCarNumberValue = (TextView) baseViewHolder.getView(R.id.textViewCarNumberValue);

            //身份证号外侧的包裹
            RelativeLayout linearLayoutOutSideIdCardNumber = (RelativeLayout) baseViewHolder.getView(R.id.linearlayoutoutsideidcardnumber);
            //身份证号
            TextView textViewIdCardNumberValue = (TextView) baseViewHolder.getView(R.id.textViewIdCardNumberValue);
            //提交时间
            TextView textViewCreateTimeRenewal = (TextView) baseViewHolder.getView(R.id.textViewCreateTimeRenewal);

            //外侧包裹两个按钮的布局
            RelativeLayout relativeLayoutTwoButton = (RelativeLayout) baseViewHolder.getView(R.id.relativeLayoutTwoButton);
            //接单 按钮
            RoundTextView roundTextViewViewTakeOrder = (RoundTextView) baseViewHolder.getView(R.id.roundTextViewViewTakeOrder);
            //完成 按钮
            RoundTextView roundTextViewViewCompleteOrder = (RoundTextView) baseViewHolder.getView(R.id.roundTextViewViewCompleteOrder);


            //外侧包裹的行车本的布局
//            LinearLayout linearLayoutOutSideDrivingBook = (LinearLayout) baseViewHolder.getView(R.id.linearlayoutoutsidedrivingbook);
            //行车本
//            BGANinePhotoLayout npl_item_moment_photos_renewal = (BGANinePhotoLayout) baseViewHolder.getView(R.id.npl_item_moment_photos_renewal);

            CommUtils.setText(textViewPersonValue, name);
            //状态值内容
            CommUtils.setText(textViewPersonOrderState, statusString);
//            CommUtils.setText(textViewPersonPhoneValue, phone);
            CommUtils.setText(textViewPersonPhoneValue, StringCodeUtils.mobileEncrypt(phone));

            CommUtils.setText(textViewCarNumberValue, licenseNo);
            CommUtils.setText(textViewCreateTimeRenewal, createTime);

            if (!TextUtils.isEmpty(idCard)) {
                CommUtils.setViewVisible(linearLayoutOutSideIdCardNumber);
                CommUtils.setText(textViewIdCardNumberValue, idCard);
            } else {
                CommUtils.setViewGone(linearLayoutOutSideIdCardNumber);
            }


//            status  0未接单  1已接单   2已完成
//            public enum CarRenewalStatus {
//            status  0未接单  1已接单   2已完成
//                    STATUS_NOT_TAKEORDER("0", "未接单"),
//                    STATUS_HAS_TAKEORDER("1", "已接单"),
//                    STATUS_HAS_COMPLETE("2", "已完成");

            if (TextUtils.equals(status, CarRenewalStatus.STATUS_NOT_TAKEORDER.getIndex())) {

                CommUtils.setViewVisible(relativeLayoutTwoButton);

                //接单 按钮 展示
                CommUtils.setViewVisible(roundTextViewViewTakeOrder);
                //完成 按钮  隐藏
                CommUtils.setViewGone(roundTextViewViewCompleteOrder);


            } else if (TextUtils.equals(status, CarRenewalStatus.STATUS_HAS_TAKEORDER.getIndex())) {

                CommUtils.setViewVisible(relativeLayoutTwoButton);

                //接单 按钮 展示
                CommUtils.setViewGone(roundTextViewViewTakeOrder);
                //完成 按钮  隐藏
                CommUtils.setViewVisible(roundTextViewViewCompleteOrder);

            } else if (TextUtils.equals(status, CarRenewalStatus.STATUS_HAS_COMPLETE.getIndex())) {

                CommUtils.setViewGone(relativeLayoutTwoButton);

                //
            }

            //车辆列表；
//            ArrayList<String> dataList = new ArrayList<>();

//            if (!TextUtils.isEmpty(drivingNotebook)) {
//
//                if (!drivingNotebook.endsWith(Parameterkey.null_value)) {
//
//                    //设置外侧布局展示|：
//                    CommUtils.setViewVisible(linearLayoutOutSideDrivingBook);
//                    dataList.add(drivingNotebook);
//
//                    //九宫格：
//                    if (npl_item_moment_photos_renewal != null) {
//                        npl_item_moment_photos_renewal.setData(dataList);
//                        npl_item_moment_photos_renewal.setDelegate(bgaNinePhotoLayoutDelegate);
//                    }
//
//                } else {
//                    CommUtils.setViewGone(linearLayoutOutSideDrivingBook);
//                }
//
//            } else {
//                //设置外侧布局展示|：
//                CommUtils.setViewGone(linearLayoutOutSideDrivingBook);
//            }

        }

    }
}
